<template>
  <div class="page">
    <div class="head">
      <h1>{{ $t('道具迁移记录') }}</h1>
    </div>
    <div class="panel">
      <ul class="list">
        <li v-for="(item,index) in records" :key="index">
          <div class="info">
            <p>{{ item.fromServerName }} → {{ item.toServerName }}</p>
            <span>{{ item.createTime | formatTime }}</span>
          </div>
          <div class="status">
            <p>{{ item.type == 1 ? '转出' : '转入'}}{{ item.goods == 1 ? '猴毛' : '蟠桃'}}</p>
            <span :class="item.type == 2 ? 'green':'red'">{{ item.type == 1 ? '-' : '+' }}{{ item.num }}</span>
          </div>
        </li>
        <infinite-loading @infinite="initData" ref="infiniteLoading2">
          <span slot="no-more"></span>
          <div slot="no-results">
            <br>
            <empty></empty>
          </div>
          <spinner slot="spinner" type="lines"></spinner>
        </infinite-loading>
      </ul>
    </div>
  </div>
</template>

<script>
  import {
    Spinner,
  } from 'vux'
  import empty from './common/empty.vue'
  import InfiniteLoading from 'vue-infinite-loading';
  export default {
    components: {
      empty,
      InfiniteLoading,
      Spinner
    },
    data() {
      return {
        records: [],
        current: 1
      }
    },
    methods: {
      initData($state) {
        this.$http
          .post(`/common/transferRecordPage`, {
            current: this.current
          })
          .then(res => {
            if (res.code == 200) {
              if (res.result.total > 0) {
                this.records = this.records.concat(res.result.records);
                $state.loaded();
                if (res.result.current < res.result.pages) {
                  this.current += 1;
                } else {
                  $state.complete();
                }
              } else {
                $state.complete();
              }
            } else {}
          })
          .catch(function(error) {});
      }
    }
  }
</script>

<style lang="scss" scoped>
  .panel {
    padding-bottom: 100px;
  }
  .list {
    li {
      border-bottom: 1px solid #dfdfdf;
      display: flex;
      justify-content: space-between;
      align-items: flex-end;
      padding: 5px 0;
      .info {
        color: $tmdark;
        p {
          font-size: 17px;
        }
        span {
          font-size: 14px;
        }
      }
      .status {
        text-align: right;
      }
      &>span {
        font-size: 20px;
      }
      .red {
        color: $red;
      }
      .green {
        color: $green;
      }
    }
  }
</style>